<?php
namespace App\Domain;

use App\Model\Member as ModelMember;

class Member {

    //根据openid查询账号是否存在
    public function getUserInfo( $openid ) {
        $model = new ModelMember();
        return $model->getUserInfo( $openid );
    }

    //根据wx返回的账号信息将值存入表中
    public function insertUserInfo( $openid, $wx_info ) {
        $model = new ModelMember();
        $data = array();
        $data['sex'] = $wx_info['gender'];
        $data['reg_time'] = time();
        $data['last_login'] = time();
        $data['last_ip'] = $_SERVER["REMOTE_ADDR"];
        $data['oauth'] = 'wx';
        $data['openid'] = $openid;
        $data['nickname'] = $wx_info['nickName'];
        $data['head_pic'] = $wx_info['avatarUrl'];
        return $model->insertUserInfo( $data );
    }
}
